<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 */

class Modules_News_Hooks_Articlelinks_Hook extends Gio_Core_Hook
{
	/**
	 * @param array $links
	 * @param string $lang
	 * @return array
	 */
	public static function filter($links, $lang)
	{
		/**
		 * Get the view instance
		 */
		$view     = Gio_Core_View::getInstance();
		
		/**
		 * Get most recently activated articles
		 * TODO: Make this variable configurable
		 */
		$limit    = 10;
//		$articles = Modules_News_Services_Article::find(0, $limit, array('status' => 'active'));
//		
//		if (count($articles) > 0) {
//			foreach ($articles as $article) {
//				$links['news_article_details'][] = array(
//														'title' => $article['title'],
//														'text'  => $article['title'],
//														'href'  => $view->url('news_article_details', $article),
//													);
//			}
//		}
		
		/**
		 * Get categories links
		 */
		$categories = Modules_Category_Services_Category::getTree($lang, 'news');
		if (count($categories) > 0) {
			foreach ($categories as $category) {
				$links['news_article_category'][] = array(
														'title' => $category['name'],
														'text'  => str_repeat('---', $category['depth']) . ' ' . $category['name'],
														'href'  => $view->url('news_article_category', $category),
													);
				
				$links['news_rss_category'][]     = array(
														'title' => $category['name'],
														'text'  => str_repeat('---', $category['depth']) . ' ' . $category['name'],
														'href'  => $view->url('news_rss_category', $category),
													);
			}
		}
		
		/**
		 * RSS links for latest articles
		 */
		$links['news_rss_index'][] = array(
										'href' => $view->url('news_rss_index', array('language' => $lang)),
									);
		
		return $links;
	}
}
